
function init(){
    $.ajax({
        url:'/lv_graduate_demands/selectAllGrad_points',
        type:'get',
        dataType:'json',
        success:function (data){
            $("#lv_grad_point_table").find('tr').remove();
            console.log(data);
            for(let i in data){
                let tr;
                // private String graduationRequirments;
                //
                // private Integer graduateDemands;
                //
                // private String graduationRequirmentsContents;


                tr = $("<tr>");
                let th1=$('<th scope="row">'+data[i].graduateDemands+'</th>' );

                let th2=$('<td>' +data[i].graduationRequirments+'</td>');

                let th3=$('<td>' +data[i].graduationRequirmentsContents+'</td>');

                tr.append(th1);
                tr.append(th2);
                tr.append(th3);
                btn_delete=$("<td> <input type=button value='删除' class='lv_button' /> </td>");
                btn_modify=$("<td> <input type=button value='修改' class='lv_button' /> </td>");
                tr.append(btn_delete);
                tr.append(btn_modify);

                $("#lv_grad_point_table").append(tr);

                //删除毕业要求指标点

                btn_delete.click(function (){


                    let tr_table=$(this).parent();
                    let td=tr_table.find("td").eq(0).html();
                    alert(td);
                    $.ajax({
                        url:'/lv_graduate_demands/deleteByGrad_Id',
                        type:'post',
                        dataType: 'json',
                        // contentType:'application/x-www-form-urlencoded; charset=UTF-8',
                        data:{"graduationRequirments":td},

                        success:function (data){
                            console.log(data);
                            if(data)
                                alert("课程目标删除成功");
                            else
                            {

                                alert("删除课程目标失败");
                            }
                        }




                    })

                    $(this).parent().remove();

                })
                //

                //修改毕业要求指标点
                btn_modify.click(function (){
                    //   调用模态框
                    //     alert("修改课程目标");
                    //显示修改框
                    // $(".lv_hide").removeClass("lv_hide");
                    //根据课程目标ID 返回一条数据
                    let t1=$(this).parent().find("td").eq(0).html();
                    $.ajax({
                        url:'/lv_graduate_demands/selectByGrad_Id',
                        type:'get',
                        dataType: 'json',
                        // contentType:'application/x-www-form-urlencoded; charset=UTF-8',
                        data:{"graduationRequirments":t1},

                        success:function (data){
                            console.log(data);
                            if(1)
                            {

                                alert("毕业要求指标点是"+t1);
                                $(".lv_grad_hide").removeClass("lv_grad_hide");


                                $("#lv_grad_point_1").val(data.graduateDemands);
                                $("#lv_grad_addgradpoint_1").val(data.graduationRequirments);
                                $("#lv_grad_addpointcontent_1").val(data.graduationRequirmentsContents);

                            }
                            else
                            {
                                alert("修改课程目标失败");
                            }
                        }




                    })

                })






            }

        }
    });
}






$(document).ready(function(){

    //    完成初始化
    init();


    // 增加课程目标
    $("#finish_lv_grad_add").click(function (){
        //private String graduationRequirments;
        //
        //     private Integer graduateDemands;
        //
        //     private String graduationRequirmentsContents;
        let Grad_Demands =$("#lv_grad_addpoint").val();
        let Grad_Requirments = $("#lv_grad_addgradpoint").val();
        let Grad_Content=$("#lv_grad_addpointcontent").val();


        console.log(Grad_Demands,Grad_Requirments,Grad_Content);
        $.ajax({
            url:'/lv_graduate_demands/insertGrad_Id',
            type:'post',
            dataType: 'json',
            // contentType:'application/x-www-form-urlencoded; charset=UTF-8',

            data:{"graduateDemands":Grad_Demands,"graduationRequirments":Grad_Requirments,
                "graduationRequirmentsContents":Grad_Content},

            success:function (data){
                console.log(data);
                if(data)
                {
                    alert("课程目标增加成功");
                    $("#lv_grad_addpoint").val("");
                    $("#lv_grad_addgradpoint").val("");
                    $("#lv_grad_addpointcontent").val("");


                    init();
                }
                else
                {

                    alert("增加课程目标失败");
                }
            }




        })
    })


    // 取消修改


    $("#cancel_lv_grad_add_1").click(function (){

        $(".lv_grad_modal").addClass("lv_grad_hide");
        $(".lv_grad_shade").addClass("lv_grad_hide");

    })

    // 提交修改


    $("#finish_lv_grad_add_1").click(function () {

        //private String graduationRequirments;
        //
        //     private Integer graduateDemands;
        //
        //     private String graduationRequirmentsContents;
        let Grad_Demands =$("#lv_grad_point_1").val();
        let Grad_Requirments = $("#lv_grad_addgradpoint_1").val();
        let Grad_Content=$("#lv_grad_addpointcontent_1").val();


        console.log(Grad_Demands,Grad_Requirments,Grad_Content);
        $.ajax({
            url:'/lv_graduate_demands/updateByGrad_Id',
            type:'post',
            dataType: 'json',
            // contentType:'application/x-www-form-urlencoded; charset=UTF-8',
            data:{"graduateDemands":Grad_Demands,"graduationRequirments":Grad_Requirments,
                "graduationRequirmentsContents":Grad_Content},

            success:function (data){
                console.log(data);
                if(data)
                {

                    alert("课程修改成功");

                    $(".lv_grad_modal").addClass("lv_grad_hide");
                    $(".lv_grad_shade").addClass("lv_grad_hide");
                    //刷新
                    init();
                }
                else
                {

                    alert("增加课程目标失败");
                }
            }




        })


    })








})


